// ���� express
const express = require('express')
// ����·�ɵ�ʵ������
const router = express.Router()

// ����joi�����ļ�
const Joi = require('../assets/joi.js')
const expressJoi = require('@escook/express-joi')

const { getdata, postdata, getstatus} = require('../api/monitor/index.js')
const { login, addUser, findUser } = require('../api/login/index.js')
const { getUser, deleteUser, updateUser, getUserDetail,getLoginUserDetail,getUserRole } = require('../api/user/index.js')
const { getStructure, addStructure, deleteStructure, editStructureRole } = require('../api/structure/index.js')
const { getRole, addUserRole, deleteRole, addRole, editRoleRight, getRoleDetail,editRole,getRoleRightDetail } = require('../api/roles/index.js')
const { getRight, editRight, deleteRight, getAllRight,addRight } = require('../api/rights/index.js')
const { getEquip, addEquip, deleteEquip, putEquip, getEquipDetail, getEquipHistory, equipLend, auditEquipLend, getUserLend, getEquipHistory2, getEquipHistory3, equipReturn, getUserLendDetail, deletetUserLend } = require('../api/equip/index.js')

const multer = require('multer')
const { upLoadImgModule, downloadModule, deleteImg, getObjImg } = require('../multer')


// ��ȡ����������
router.post('/getdata',expressJoi(Joi.getdata), getdata)
router.post('/getstatus',expressJoi(Joi.getstatus), getstatus)
// �����豸
router.post('/postdata',expressJoi(Joi.postdata), postdata)



// �ϴ�ͼƬ
router.post(
    "/hold/imgload",
    multer({
      //�����ļ��洢·��
      dest: "public/images",
    }).array("files", 3),
    upLoadImgModule
)

// ����ͼƬ
router.get("/hold/imgdownload", downloadModule)
// ɾ���豸
router.delete("/hold/img", deleteImg)
// ��ȡ�豸ͼƬ��Ϣ
router.get("/hold/img", getObjImg)




// ��ѯ�����豸
router.get('/equipment/equip', getEquip)

// �����豸
router.post('/equipment/equip', expressJoi(Joi.addEquip), addEquip)

// ɾ���豸
router.delete('/equipment/equip', expressJoi(Joi.getRight), deleteEquip)

// ɾ�����ü�¼
router.delete('/equipment/lend', expressJoi(Joi.getRight), deletetUserLend)

// �����豸
router.put('/equipment/equip', expressJoi(Joi.putEquip), putEquip)

// ����id��ѯ�豸����
router.get('/equipment/detail', expressJoi(Joi.getRight), getEquipDetail)

// ����������ѯ�豸���ü�¼
router.get('/equipment/phistory', getEquipHistory)
// ����������ѯ�豸���ü�¼
router.get('/equipment/ehistory', expressJoi(Joi.getRight), getEquipHistory2)

// ��ѯ���������
router.get('/equipment/whistory', getEquipHistory3)

// �����豸
router.post('/equipment/lend', expressJoi(Joi.equipLend), equipLend)
// �黹�豸
router.post('/equipment/return', expressJoi(Joi.equipReturn), equipReturn)

// ��˽����豸
router.put('/equipment/audit', expressJoi(Joi.auditEquipLend), auditEquipLend)

// ��ѯѧ�����ü�¼
router.get('/equipment/user', expressJoi(Joi.getUserLend), getUserLend)

// ����id��ѯ���ü�¼
router.get('/equipment/lenddetail', expressJoi(Joi.getRight), getUserLendDetail)




// �ύ�˺������¼
router.post('/api/login', expressJoi(Joi.userSchema), login)


router.post('/admin/finduser', expressJoi(Joi.findUser), findUser)

// ����Ҫid��ȡ��¼�û�����
router.get('/admin/logindetail', getLoginUserDetail)

// ����id��ȡ�û�����
router.get('/admin/detail', expressJoi(Joi.deleteUser),getUserDetail)

// ע�����û�
router.post('/admin/adduser', expressJoi(Joi.addUserSchema),addUser)

// ��ȡ�û��б�
router.get('/admin/user', getUser)

// ɾ���û�
router.delete('/admin/deleteuser',expressJoi(Joi.deleteUser), deleteUser)

// �༭�û�
router.put('/admin/edituser', expressJoi(Joi.editUserSchema), updateUser)

// ��ȡ�û���ɫ
router.get('/admin/getuserrole',expressJoi(Joi.getUserRole), getUserRole)


// ��ȡ�ܹ�
router.get('/admin/getstructure', getStructure)

// ���ӷ�֧
router.post('/admin/addstructure', expressJoi(Joi.addStructure), addStructure)

// ɾ����֧
router.delete('/admin/deletestructure', expressJoi(Joi.deleteStructure), deleteStructure)

// �޸ķ�֧
router.put('/admin/editstructure', expressJoi(Joi.editStructure), editStructureRole)




// ��ȡ��ɫ�б�
router.get('/admin/role', expressJoi(Joi.getlistSchema), getRole)

// ��ȡ��ɫ����
router.get('/admin/getroledetail', expressJoi(Joi.deleteRole), getRoleDetail)
// ��ȡ��ɫȨ�޵�����
router.get('/admin/getrolerightdetail', expressJoi(Joi.deleteRole), getRoleRightDetail)

// ���û����ӽ�ɫ
router.post('/admin/adduserrole', expressJoi(Joi.editUserRole), addUserRole)

// ���ӽ�ɫ
router.post('/admin/addrole', expressJoi(Joi.addRole), addRole)

// �༭��ɫ
router.put('/admin/editrole', expressJoi(Joi.editRole), editRole)

// ɾ����ɫ
router.delete('/admin/role', expressJoi(Joi.deleteRole), deleteRole)

// �༭��ɫȨ��
router.put('/admin/editroleright', expressJoi(Joi.editRoleRight), editRoleRight)




// ����id��ȡȨ������
router.get('/admin/getright', expressJoi(Joi.getRight), getRight)

// ����id�༭Ȩ������
router.put('/admin/editright', expressJoi(Joi.editRight), editRight)

// ����idɾ��Ȩ��
router.delete('/admin/deleteright', expressJoi(Joi.getRight), deleteRight)

// ��ѯ����Ȩ��
router.get('/admin/getallright', getAllRight)

// ����Ȩ��
router.post('/admin/addright', expressJoi(Joi.addRight),addRight)



module.exports = router

